import React from 'react'
import { Route, withRouter, Redirect } from 'react-router-dom'
import token from '../../utils/token.js'

export default ({path, component: Component}) => {
    return (
        <Route path={path} render={() => {
            // 向Component组件注入路由相关属性
            const WrapComponent = withRouter(Component)
            // 判断token是否存在，如果存在就正常显示；否则跳转到登录页
            const t = token.getToken()
            return t? <WrapComponent/>: <Redirect to='/login'/>
        }}/>
    )
}